﻿using System;
using Hjt212Parser;
using System.Linq;
using Biz.Buffer;
using Biz.EF.Platform;
using log4net;


namespace Biz.Process
{
    /// <summary>
    /// 主要处理校时、阀门状态等指令
    /// </summary>
    public class UplineCmdInstructionTotal
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(UplineCmdInstructionTotal));

        public static void Process3052(PlatformContext pCtx, string content)
        {
            try
            {
                var mn = Parser.GetStringByKey("MN", content);
                if (string.IsNullOrEmpty(mn)) return;
                var letport = CommonInformation.GetLetportByMn(mn);
                if (letport == null) return;
                var datatime = Parser.GetDateTimeByKey("SystemTime", content);
                if (datatime == null) return;
                var isSuccess = Parser.GetStringByKey("IsSucceed", content);
                var per = Parser.GetStringByKey("Per", content);
                var item = new 反控阀门
                {
                    企业基本信息ID = letport.企业基本信息ID,
                    设备信息ID = letport.ID,
                    时间 = datatime.Value,
                    阀门状态 = MyConvertor.Int2Chinese(per),
                    阀门执行事项ID = 303,
                    执行结果标志ID = isSuccess.Equals("1") ? 603 : 604,
                    QN = Parser.GetStringByKey("QN", content)

                };
                pCtx.反控阀门.Add(item);
                pCtx.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }

    }
}
